﻿<UserControl x:Class="AutomationMLMapper.Controls.InstanceListControl"
			 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
			 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
			 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:MarkupExtensions="clr-namespace:AutomationMLMapper.Controls.MarkupExtensions"
			 xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
			 xmlns:local="clr-namespace:AutomationMLMapper.Controls"
             xmlns:ribbon="clr-namespace:Microsoft.Windows.Controls.Ribbon;assembly=RibbonControlsLibrary"
             xmlns:ConvertersAndTemplateSelectors="clr-namespace:AutomationMLMapper.Controls.ConvertersAndTemplateSelectors"
             xmlns:Properties="clr-namespace:AutomationMLMapper.Properties" mc:Ignorable="d" 
			 d:DesignHeight="300" d:DesignWidth="300">
	<UserControl.Resources>
		<ResourceDictionary>
			<ResourceDictionary.MergedDictionaries>
				<ResourceDictionary Source="/AutomationMLMapper;component/StyleResources/ListStyle.xaml"/>
				<ResourceDictionary Source="/AutomationMLMapper;component/StyleResources/Templates.xaml"/>
			</ResourceDictionary.MergedDictionaries>
			<ConvertersAndTemplateSelectors:BoolToVisibilityConverter FalseValue="Collapsed" x:Key="btvc" />
		</ResourceDictionary>
	</UserControl.Resources>
	<Grid>
        <Grid.InputBindings>
             <KeyBinding Command="{Binding LoadSystemCommand}" Gesture="Ctrl+S"/>
        </Grid.InputBindings>

        <Grid.RowDefinitions>
			<RowDefinition Height="Auto"></RowDefinition>
			<RowDefinition Height="Auto"></RowDefinition>
			<RowDefinition Height="*"></RowDefinition>
			<RowDefinition Height="Auto"></RowDefinition>
			<RowDefinition Height="Auto"></RowDefinition>
		</Grid.RowDefinitions>
		<Border Margin="1"  Grid.Row="0" BorderThickness="1" CornerRadius="1" BorderBrush="#FF565656">
			<Grid Margin="1">
				<Grid.ColumnDefinitions>
					<ColumnDefinition Width="Auto"></ColumnDefinition>
					<ColumnDefinition Width="*"></ColumnDefinition>
					<ColumnDefinition Width="Auto"></ColumnDefinition>
				</Grid.ColumnDefinitions>

                <TextBlock Grid.Column="0"  FontWeight="Bold" Margin="5,0,5,0" VerticalAlignment="Center">                                             
                    <Run Text="Name of the "/>
                    <Run Text="{Binding Path=SystemType}"/>
                </TextBlock>
                
				<TextBlock Grid.Column="1" Margin="0,0,5,0" Text="{Binding Path=Name}" VerticalAlignment="Center"></TextBlock>

                <ribbon:RibbonButton Grid.Column="2" 
                                    SmallImageSource="{MarkupExtensions:ImageResolution Source=SCLib.ico, Size=24}" 
                                    Command="{Binding LoadSystemCommand}" 
                                    KeyTip="S"
                                    ToolTipImageSource="/AutomationMLMapper;component/Images/Info.ico"
					                ToolTipDescription="{x:Static Properties:Resources.SystemDefinitionAutomationMLDocumentDescription}" 
                                    ToolTipTitle="{x:Static Properties:Resources.SystemDefinitionAutomationMLDocument}">
                </ribbon:RibbonButton>
                
			</Grid>
		</Border>

		<TextBlock Grid.Row="1" Style="{StaticResource HeaderTextBlock}" Text="{x:Static Properties:Resources.ListOfSystemUnitClasses}"></TextBlock>
		
		<ListView Grid.Row="2" IsSynchronizedWithCurrentItem="True" HorizontalAlignment="Stretch"
                  Name="ListOfSimulatedClasses" 
                  VirtualizingStackPanel.IsVirtualizing="True"
                  VirtualizingStackPanel.VirtualizationMode="Recycling"
                  ScrollViewer.IsDeferredScrollingEnabled="True"
                  DataContext="{Binding ClassesCollection}"                 
                  ItemsSource="{Binding RelativeSource={RelativeSource Self}, Path=DataContext.View}"
                  Margin="0,5,0,0" >

			<ListView.View>
				<GridView>
					<GridViewColumn Width="Auto" CellTemplate="{StaticResource NameOutputTemplate}" HeaderContainerStyle="{StaticResource ColumnHeaderStyle}">
						<GridViewColumn.HeaderTemplate>
							<DataTemplate>
								<StackPanel Orientation="Horizontal">
                                    <Image Source="{MarkupExtensions:ImageResolution Source=SC.ico, Size=24}"></Image>
									<TextBlock Margin="5,0,0,0" Text="SystemUnitClass"></TextBlock>
								</StackPanel>
							</DataTemplate>
						</GridViewColumn.HeaderTemplate>
					</GridViewColumn>

					<GridViewColumn Width="Auto" x:Name="SupportedRolesColumn" HeaderContainerStyle="{StaticResource ColumnHeaderStyle}">
						<GridViewColumn.HeaderTemplate>
							<DataTemplate>
								<local:CollapsibleColumnHeader HeaderImageSource="{MarkupExtensions:ImageResolution Source=SRC.ico, Size=16}" 
															   ShowColumn="{Binding ElementName=ListOfSimulatedClasses, Path=DataContext.ShowSupportedRoles, Mode=TwoWay}"
															   ExpandColumn="{Binding ElementName=ListOfSimulatedClasses, Path=DataContext.ExpandSupportedRoles, Mode=TwoWay}"
															   HeaderToolTip="Show Supported Roles of the SystemUnitClass" 
                                                               HeaderName="Supported RoleClass" Column="{Binding ElementName=SupportedRolesColumn}">
								</local:CollapsibleColumnHeader>
							</DataTemplate>
						</GridViewColumn.HeaderTemplate>

						<GridViewColumn.CellTemplate>
							<DataTemplate>
								<local:CAEXCollectionView AllowAdd="False" AllowDelete="False"
													  DataContext="{Binding RolesCollection}" AllowEditElement ="False"
													  Visibility="{Binding ElementName=ListOfSimulatedClasses, Path=DataContext.ShowSupportedRoles, Converter={StaticResource btvc}}"/>
							</DataTemplate>
						</GridViewColumn.CellTemplate>
					</GridViewColumn>

					<GridViewColumn x:Name="InstanceColumn" Width="Auto" HeaderContainerStyle="{StaticResource ColumnHeaderStyle}">
						<GridViewColumn.HeaderTemplate>
							<DataTemplate>
								<local:CollapsibleColumnHeader HeaderImageSource="{MarkupExtensions:ImageResolution Source=IE.ico, Size=16}"
															   ShowColumn="{Binding ElementName=ListOfSimulatedClasses, Mode=TwoWay, Path=DataContext.ShowInstanceOfClass}"
															   ExpandColumn="{Binding ElementName=ListOfSimulatedClasses, Mode=TwoWay, Path=DataContext.ExpandInstanceOfClass}"
															   HeaderToolTip="Show Internal Element Instances of the SystemUnitClass" 
                                                               HeaderName="Internal Element Instance" Column="{Binding ElementName=InstanceColumn}">
								</local:CollapsibleColumnHeader>
							</DataTemplate>
						</GridViewColumn.HeaderTemplate>

						<GridViewColumn.CellTemplate>
							<DataTemplate>
								<local:CAEXCollectionView HorizontalAlignment="Stretch"
													  Visibility="{Binding ElementName=ListOfSimulatedClasses, Path=DataContext.ShowInstanceOfClass, Converter={StaticResource btvc}}" 
                                                      AddToolTipDescription="Create an InternalElement as an instance of the selected SystemUnitClass"
                                                      DeleteToolTipDescription="Delete the InternalElement"
													  DataContext="{Binding InstancesCollection}"/>
							</DataTemplate>
						</GridViewColumn.CellTemplate>
					</GridViewColumn>
                </GridView>
			</ListView.View>

            <ListView.ItemContainerStyle>
                <Style TargetType="ListBoxItem">
                    <Setter Property="HorizontalAlignment" Value="Stretch" />
                    <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
                    <Setter Property="VerticalContentAlignment" Value="Top"/>
                </Style>
            </ListView.ItemContainerStyle>
            <ListView.GroupStyle>
                <GroupStyle ContainerStyle="{StaticResource ListGroupStyle}">
                </GroupStyle>
            </ListView.GroupStyle>
        </ListView>		
	</Grid>
</UserControl>
